//
//  UINavigationController+Manager.m
//  高仿暴走斗图
//
//  Created by huangsongyao on 16/3/14.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "UINavigationController+Manager.h"
#import "HSYBaseNavigationController+UI.h"
#import "UIImage+Canvas.h"

@implementation UINavigationController (Manager)

- (NSInteger)findNavigationControllerSubViewControllerIndexToViewController:(id)viewController {
    
    NSInteger index = -1;
    
    for (NSInteger i = 0; i <self.navigationController.viewControllers.count; i++) {
        
        UIViewController *vc = self.navigationController.viewControllers[i];
        if ([vc isEqual:viewController]) {
            index = i;
        }
    }
    
    return index;
}



#pragma mark - Add Transition Animation

- (void)standardAnimationWithController:(UIViewController *)viewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options changesCompletion:(void (^)(void))completion {
    
    [UIView beginAnimations:nil context:NULL];
    
    [self addShadowToView:viewController.view];
    [UIView setAnimationDuration:duration];
    [UIView transitionWithView:self.view duration:duration options:options animations:completion completion:NULL];
    [UIView commitAnimations];
}


- (void)coreAnimationWithController:(UIViewController *)viewController duration:(NSTimeInterval)duration type:(NSString *)type subtype:(NSString *)subtype changesCompletion:(void (^)(void))completion {
    
    CATransition *trans = [CATransition animation];
    [trans setDuration:duration];
    [trans setType:type];
    [trans setSubtype:subtype];
    [self.view.layer addAnimation:trans forKey:kCATransition];
    [self addShadowToView:viewController.view];
    
    completion();
}


#pragma mark - Animation Time

- (CGFloat)animationDuration {
    
    return 0.50f;
}


#pragma mark - Add Shadow

- (void)addShadowToView:(UIView *)view {
    
    if (!view) {
        return;
    }
    [HSYBaseNavigationController showShadowInContentView:view];
}

#pragma mark - Screenshots 

- (UIImageView *)getScreenImageViewForFrame:(CGRect)frame captureImageInView:(UIView *)view {
    
    UIImageView *screenshots = [[UIImageView alloc] initWithImage:[UIImage captureImageInView:view]];//先画出一张未push前的nav的效果图
    screenshots.frame = frame;
    [self addShadowToView:screenshots];
    
    return screenshots;
}

- (UIImageView *)getScreenImageViewForFrame:(CGRect)frame andImage:(UIImage *)image {
    
    UIImageView *screenshots = [[UIImageView alloc] initWithImage:image];//先画出一张未push前的nav的效果图
    screenshots.frame = frame;
    [self addShadowToView:screenshots];
    
    return screenshots;

}

@end
